package com.cci.kangdao.fieldService.controller;

import com.cci.kangdao.dto.PagedRequest;
import com.cci.kangdao.aop.RequestBodyThreadLocal;
import com.cci.kangdao.fieldService.dto.request.CreateInvestigationRequest;
import com.cci.kangdao.fieldService.dto.request.CreateWorkOrderRequest;
import com.cci.kangdao.fieldService.dto.request.DeleteInvestigationRequest;
import com.cci.kangdao.fieldService.dto.request.DeleteReportRequest;
import com.cci.kangdao.fieldService.dto.request.SelectTemplateRequest;
import com.cci.kangdao.fieldService.dto.request.StartItemServiceRequest;
import com.cci.kangdao.fieldService.dto.request.StartServiceRequest;
import com.cci.kangdao.fieldService.dto.request.EditTemplateSectionRequest;
import com.cci.kangdao.fieldService.dto.request.UpdateReportRequest;
import com.cci.kangdao.fieldService.dto.request.WorkOrderCompletionRequest;
import com.cci.kangdao.fieldService.dto.request.WorkOrderUpgradeRequest;
import com.cci.kangdao.fieldService.service.FieldServiceService;
import com.cci.kangdao.utilTool.JsonUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @author William Du
 * @date 2020/1/2
 */
@Controller
@RequestMapping("/fieldService")
public class FieldServiceController {

    @Resource
    private FieldServiceService fieldServiceService;

    @RequestMapping(value = "/getOpenItemList.aspx")
    public void getOpenItemList(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        PagedRequest pagedRequest = new PagedRequest();
        pagedRequest.setPage(page);
        pagedRequest.setPageSize(pageSize);
        fieldServiceService.getOpenItemList(pagedRequest);
    }

    @RequestMapping(value = "/getItem.aspx")
    public void getItem(@RequestParam("itemId") Long itemId) {
        fieldServiceService.getItem(itemId);
    }

    @RequestMapping(value = "/startItemService.aspx")
    public void startItemService() {
        StartItemServiceRequest startItemServiceRequest = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), StartItemServiceRequest.class);
        fieldServiceService.startItemService(startItemServiceRequest);
    }

    @RequestMapping(value = "/getItemList.aspx")
    public void getItemList(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        PagedRequest pagedRequest = new PagedRequest();
        pagedRequest.setPage(page);
        pagedRequest.setPageSize(pageSize);
        fieldServiceService.getItemList(pagedRequest);
    }

    @RequestMapping(value = "/createWorkOrder.aspx")
    public void createWorkOrder() {
        CreateWorkOrderRequest workOrderRequest = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), CreateWorkOrderRequest.class);
        fieldServiceService.createWorkOrder(workOrderRequest);
    }

    @RequestMapping(value = "/getOrderList.aspx")
    public void getWorkOrderList(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        PagedRequest pagedRequest = new PagedRequest();
        pagedRequest.setPage(page);
        pagedRequest.setPageSize(pageSize);
        fieldServiceService.getWorkOrderList(pagedRequest);
    }

    @RequestMapping(value = "/getOrder.aspx")
    public void getWorkOrder(@RequestParam("orderId") Long orderId) {
        fieldServiceService.getOrder(orderId);
    }

    @RequestMapping(value = "/getWorkOrderDetail.aspx")
    public void getWorkOrderDetail(@RequestParam("orderId") Long orderId) {
        fieldServiceService.getOrderDetail(orderId);
    }

    @RequestMapping(value = "/startService.aspx",method = RequestMethod.POST)
    public void startService() {
        StartServiceRequest workOrderRequest = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), StartServiceRequest.class);
        fieldServiceService.startService(workOrderRequest.getOrderId());
    }

    @RequestMapping(value = "/getInvestigationList.aspx",method = RequestMethod.GET)
    public void getInvestigationList(@RequestParam("orderId") Long orderId) {
        fieldServiceService.getInvestigationList(orderId);
    }

    @RequestMapping(value = "/createInvestigation.aspx",method = RequestMethod.POST)
    public void createInvestigation() {
        CreateInvestigationRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), CreateInvestigationRequest.class);
        fieldServiceService.createInvestigation(request);
    }

    @RequestMapping(value = "/deleteInvestigation.aspx",method = RequestMethod.POST)
    public void disableInvestigation() {
        DeleteInvestigationRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), DeleteInvestigationRequest.class);
        fieldServiceService.deleteInvestigation(request);
    }

    @RequestMapping(value = "/getReportList.aspx",method = RequestMethod.GET)
    public void getReportList(@RequestParam("orderId") Long orderId, @RequestParam("investigationId") Long investigationId) {
        fieldServiceService.getReportList(orderId, investigationId);
    }

    @RequestMapping(value = "/getAvailableTemplateList.aspx",method = RequestMethod.GET)
    public void getAvailableTemplateList(@RequestParam("orderId") Long orderId, @RequestParam("investigationId") Long investigationId) {
        fieldServiceService.getAvailableTemplateList(orderId, investigationId);
    }

    @RequestMapping(value = "/selectTemplate.aspx",method = RequestMethod.POST)
    public void checkTemplate() {
        SelectTemplateRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), SelectTemplateRequest.class);
        fieldServiceService.selectTemplate(request);
    }

    @RequestMapping(value = "/updateReport.aspx")
    public void updateReport() {
        UpdateReportRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), UpdateReportRequest.class);
        fieldServiceService.updateReport(request);
    }

    @RequestMapping(value = "/deleteReport.aspx")
    public void deleteReport() {
        DeleteReportRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), DeleteReportRequest.class);
        fieldServiceService.deleteReport(request);
    }

    @RequestMapping(value = "/getTemplateSection.aspx",method = RequestMethod.GET)
    public void getTemplateSection(
                                    @RequestParam("reportId") Long reportId,
                                   @RequestParam(value = "sectionId", required = false) Long sectionId
    ) {
        fieldServiceService.getTemplateSection(reportId, sectionId);
    }

    @RequestMapping(value = "/submitTemplateSection.aspx",method = RequestMethod.POST)
    public void submitTemplateSection() {
        EditTemplateSectionRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), EditTemplateSectionRequest.class);
        fieldServiceService.submitTemplateSection(request);
    }

    @RequestMapping(value = "/finishTemplateSection.aspx",method = RequestMethod.POST)
    public void finishTemplateSection() {
        EditTemplateSectionRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), EditTemplateSectionRequest.class);
        fieldServiceService.finishTemplateSection(request);
    }

    @RequestMapping(value = "/getDictionary.aspx",method = RequestMethod.GET)
    public void getDictionary(@RequestParam(value = "type") String type,
                              @RequestParam(value = "keyword",required = false) String keyword){
        fieldServiceService.getDictionary(type,keyword);
    }

    @RequestMapping(value = "/workOrderUpgrade.aspx",method = RequestMethod.POST)
    public void workOrderUpgrade(){
        WorkOrderUpgradeRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), WorkOrderUpgradeRequest.class);
        fieldServiceService.workOrderUpgrade(request);
    }

    @RequestMapping(value = "/getUpgradeList.aspx",method = RequestMethod.GET)
    public void getUpgradeList(@RequestParam(value = "orderId") Long orderId){
        fieldServiceService.getUpgradeList(orderId);
    }

    @RequestMapping(value = "/completion.aspx",method = RequestMethod.POST)
    public void completion(){
        WorkOrderCompletionRequest request = JsonUtils.toJavaObject(RequestBodyThreadLocal.get(), WorkOrderCompletionRequest.class);
        fieldServiceService.workOrderCompletion(request);
    }

}
